/**
 * 合并两个有序链表
 */

function mergeLink(l1, l2){
    if(!l1 && !l2) return null
    // 这需要新建一个列表的节点, 作为新的输出的链表出现
    let newL = new linkNode()
    if(!l1) return newL.next = l2
    if(!l2) return newL.next = l1

    while(l1 && l1){
        if(l1.val < l2.val){
            newL.next = l1
            newL = newL.next
            l1 = l1.next
        }else {
            newL.next = l2
            newL = newL.next
            l2 = l2.next
        }
    }
    while (l1) {
        newL.next = l1
        newL = newL.next
        l1 = l1.next
    }
    while(l2) {
        newL.next = l2
        newL = newL.next
        l2 = l2.next
    }
    return newL
}



function mergeSortedArr (A, B) {
    if(A.length === 0) return B
    if(B.length ===0 ) return A
    const len_a  = a.length
    const len_b = b.length
    let i =0;
    let j =0;
    let count = 0

    while(i < len_a && j < len_b) {
        if(A[i] < B[j]) {
            A[count] = A[i]
            i ++
            count ++
        }else {
            A[count] = B[j]
            j ++
            count ++
        }
    }
    while (i < len_a) {
        A[count] = A[i]
        i++
        count ++
    }

    while (j<len_b){
        A[count] = B[j]
        j++
        count ++
    }
}

